package com.chinasoft.rentalservice.controller;

import com.chinasoft.ms.dto.RentalDTO;
import com.chinasoft.ms.dto.RentalRecordDTO;
import com.chinasoft.ms.pojo.Result;
import com.chinasoft.rentalservice.service.RentalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class RentalMicroController {

    @Autowired
    private RentalService rentalService;

    @GetMapping("/rental/carId/{carId}")
    public RentalRecordDTO QueryByCarId(@PathVariable Long carId) {
        return rentalService.getRentalByCarId(carId);
    }

    @GetMapping("/rental2/carId/{carId}")
    public RentalRecordDTO QueryByCarId2(@PathVariable Long carId) {
        return rentalService.getRental2ByCarId(carId);
    }

    @PutMapping("/status/{rentalId}")
    boolean updateRentalStatus(@PathVariable("rentalId") Long rentalId) {
        System.out.println("rentalId:" + rentalId);
        boolean success = rentalService.updateStatus(rentalId, "1");
        return success ? true  : false;
    }

    @GetMapping("/getRentalById/{rentalId}")
    RentalDTO getRentalById(@PathVariable Long rentalId){
        return rentalService.getRentalById(rentalId);
    }

    @PostMapping("/addRental")
    public boolean addRental(@RequestBody RentalRecordDTO rentalDTO) {
        boolean success = rentalService.addRental(rentalDTO);
        return success ? true : false;
    }
}
